//////////////////////////////////////////////////////////////////////////////////
//
//	AvaMods BotMod
//		- Version 1.4
//		- 04.14.2008
//		- diamond-optic
//
//////////////////////////////////////////////////////////////////////////////////
//
// Information:
//
//   - Custom bot script used for extra control
//     over the bots on the AvaMods server. (no longer used!)
//
//   - Bots change class randomly, bots occasionally dont
//     have any weapon other then spade, also prevents
//     bots from having MGs, Snipers, & bipod weapons..
//
//   - If a bot has or picks up a rocket launcher, there is a
//     random chance that theyre weapons will be stripped and
//     they will be given either 3 grenades or a pistol..
//
//   - Bots score will be reset to 0:0:0 when they join game.
//
//   - 5 minutes after a bot joins, their score will be checked,
//     if they have 0 kills & deaths they will be removed...
//
//   - When a bot joins, a random time between 15 & 25 minutes
//     is selected, after that time the bots score is checked
//     and it is kicked if its score is 0:0 or it has less then
//     a 0.50 ratio. If it passes these checks, the task is reset
//     at another random time between 10 & 20 minutes...
//
//////////////////////////////////////////////////////////////////////////////////
//
// Changelog:
//
//   - 05.27.2006 Version 1.0
//  	  Initial release
//
//   - 06.06.2006 Version 1.1
//  	  Improved tasks & checks
//	  Added kick bot for poor score or zero score
//  	  Added checking for rocket in hand
//
//   - 06.25.2006 Version 1.1b
//  	  Adjusted some task times & random numbers
//
//   - 07.24.2006 Version 1.2
//  	  Adjusted putinserver "change_class" task time
//	  Cleaned up code
//
//   - 08.06.2006 Version 1.3
//  	  Changed some returns
//	  Cleaned up code a bit more
//
//   - 04.14.2008 Version 1.4
//  	  Marked plugin as replaced
//	  Updated public cvar format
//	  Cleaned up code a bit
//
//////////////////////////////////////////////////////////////////////////////////

#include <amxmodx>
#include <dodx>
#include <dodfun>
#include <fun>

#define VERSION "1.3"
#define SVERSION "v1.3 - by diamond-optic (www.AvaMods.com)"

public plugin_init()
{
	register_plugin("AvaMods BotMod",VERSION,"diamond-optic")
	register_cvar("avamods_botmod_stats",SVERSION,FCVAR_SERVER|FCVAR_SPONLY)
	
	register_event("ResetHUD","check_class","be")
	
	register_event("CurWeapon","Event_CurWeapon","be","1=1")
}

public client_putinserver(id)
{
	if(is_user_bot(id) && is_user_connected(id))
		{
		if(task_exists(id))
			remove_task(id)

		set_task(0.1,"change_class",id)
		set_task(1.0,"bot_score",id)
		set_task(random_float(300.0,480.0),"bot_kick_zero",id)
		set_task(random_float(Float:900.0,Float:1500.0),"bot_kick",id)
		}
}

public client_disconnect(id)
	if(is_user_bot(id) && task_exists(id))
		remove_task(id)

public Event_CurWeapon(id)
{
	if(!is_user_alive(id) || !is_user_connected(id) || !is_user_bot(id))
		return PLUGIN_CONTINUE
		
	new ammo,clip,zGun = dod_get_user_weapon(id,clip,ammo)
	
	if(zGun == DODW_BAZOOKA || zGun == DODW_PIAT || zGun == DODW_PANZERSCHRECK)
		{
		if(random_num(0,5) == 3)
			{
			strip_user_weapons(id)
		
			if(get_user_team(id) == 1)
				{
				give_item(id,"weapon_handgrenade")
				give_item(id,"weapon_handgrenade")
				give_item(id,"weapon_handgrenade")
				}
			else if(get_user_team(id) == 2)
				{
				give_item(id,"weapon_stickgrenade")
				give_item(id,"weapon_stickgrenade")
				give_item(id,"weapon_stickgrenade")
				}
			}
		else if(random_num(0,1) == 1)
			{
			strip_user_weapons(id)
		
			if(get_user_team(id) == 1)
				give_item(id,"weapon_colt")
			else if (get_user_team(id) == 2)
				give_item(id,"weapon_luger")
			}
		}
		
	return PLUGIN_CONTINUE
}

public bot_kick_zero(id)
{
	if(!is_user_connected(id) && !is_user_bot(id))
		return PLUGIN_CONTINUE
	
	if(!dod_get_user_kills(id) && !dod_get_pl_deaths(id))
		server_cmd("kick #%d Zero Bot Score - Removed...",get_user_userid(id))
		
	return PLUGIN_HANDLED
}		

public bot_kick(id)
{
	if(!is_user_connected(id) && !is_user_bot(id))
		return PLUGIN_HANDLED

	new bot_deaths = dod_get_pl_deaths(id)
	
	if(!bot_deaths)
		bot_deaths = 1
	
	new Float:kd_ratio = floatdiv(float(dod_get_user_kills(id)),float(bot_deaths))
	
	if(kd_ratio < 0.5)
		{
		server_cmd("kick #%d Bad Bot Score - Removed...",get_user_userid(id))
		
		return PLUGIN_HANDLED
		}
		
	else
		set_task(random_float(Float:600.0,Float:1200.0),"bot_kick", id)
		
	return PLUGIN_HANDLED
}

public bot_score(id)
{
	if(!is_user_connected(id) && !is_user_bot(id))
		return PLUGIN_HANDLED

	dod_set_user_kills(id,0,1)
	dod_set_user_score(id,0,1)
	dod_set_pl_deaths(id,0,1)
	
	return PLUGIN_HANDLED
}

public check_class(id)
{
	if(!is_user_connected(id) || !is_user_bot(id) || !is_user_alive(id))
		return PLUGIN_CONTINUE
		
	new bot_class = dod_get_user_class(id)
	
	if(bot_class == DODC_BAZOOKA || bot_class == DODC_PANZERJAGER || bot_class == DODC_PIAT || bot_class == DODC_30CAL || bot_class == DODC_MG34 || bot_class == DODC_MG42)
		set_task(1.0,"change_class",id)

	else if((get_user_team(id) == 1 || get_user_team(id) == 2) && random_num(0,15) == 7)
			set_task(0.5,"strip_bot", id)

	else if(random_num(0, 5) == 3)
		set_task(1.0,"change_class",id)
		
	return PLUGIN_CONTINUE
}

public change_class(id)
{
	if(!is_user_connected(id) || !is_user_bot(id))
		return PLUGIN_HANDLED
			
	if(get_user_team(id) == 1 && dod_get_map_info(MI_ALLIES_TEAM) == 1)	//allies & brits?
		{
		switch(random_num(0,2))
			{
			case 0:	dod_set_user_class(id, DODC_ENFIELD)
			case 1:	dod_set_user_class(id, DODC_STEN)
			case 2:	dod_set_user_class(id, DODC_PIAT)
			}
		return PLUGIN_HANDLED
		}
	else if (get_user_team(id) == 1)	//allies
		{
		switch(random_num(0,4))
			{
			case 0:	dod_set_user_class(id, DODC_GARAND)
			case 1:	dod_set_user_class(id, DODC_CARBINE)
			case 2:	dod_set_user_class(id, DODC_GREASE)
			case 3:	dod_set_user_class(id, DODC_THOMPSON)
			case 4:	dod_set_user_class(id, DODC_BAZOOKA)
			}
		return PLUGIN_HANDLED
		}
	else if (get_user_team(id) == 2)	//axis
		{
		switch(random_num(0,4))
			{
			case 0:	dod_set_user_class(id, DODC_KAR)
			case 1:	dod_set_user_class(id, DODC_K43)
			case 2:	dod_set_user_class(id, DODC_MP40)
			case 3:	dod_set_user_class(id, DODC_MP44)
			case 4:	dod_set_user_class(id, DODC_PANZERJAGER)
			}
		return PLUGIN_HANDLED
		}
		
	return PLUGIN_HANDLED
}

public strip_bot(id)
{
	if(!is_user_connected(id) && !is_user_bot(id))
		return PLUGIN_HANDLED
		
	strip_user_weapons(id)
	give_item(id,"weapon_spade")

	return PLUGIN_HANDLED
}
